<?php
namespace app\index\controller;

use app\index\model\EnginBaoModel;
use app\index\model\EnginModel;
use app\index\model\EnginMuModel;
use think\Controller;
use think\Db;
use think\facade\Config;
use think\Request;

class Test extends Controller
{
    public function test(){

    }

    public function upd_engin_baonums(){
        die;
        $enginidArr = [];
        $enginidArr = EnginModel::where(['deleted_user'=>0])->column('id');
        foreach ($enginidArr as $enid){
            $muArr = EnginMuModel::field('id,comid')->where(['enginid'=>$enid,'deleted_user'=>0])->select()->toArray();
            foreach ($muArr as $muinfo){
                $sonsArr = EnginMuModel::where(Db::raw("find_in_set(".$muinfo['id'].",`parents`)"))->where(['enginid'=>$enid])->column('id');

                $baonum = EnginBaoModel::where(['comid'=>$muinfo['comid'],'enginid'=>$enid,'deleted_user'=>0])
                    ->where('status','=',1)->where('muid','in',$sonsArr)->count();

                $baoshennum = EnginBaoModel::where(['comid'=>$muinfo['comid'],'enginid'=>$enid,'deleted_user'=>0])
                    ->where('status','in',[0,1,2])->where('muid','in',$sonsArr)->count();

                EnginMuModel::where(['id'=>$muinfo['id']])->update([
                    'baonum' => $baonum,
                    'baoshennum' => $baoshennum,
                ]);
            }

            dump($enid);
        }

        dump('success');
    }



}
